﻿using System;
using System.Linq;

namespace SwimmingCompetitions
{
    [Serializable]
    public class Rank
    {
        /// <summary>
        /// Only these instances shall be used as values for grid.
        /// </summary>
        public static readonly Rank[] Ranks = new[]
                                         {
                                             new Rank("0"), 
                                             new Rank("I"), 
                                             new Rank("II"), 
                                             new Rank("III"), 
                                             new Rank("КМС"), 
                                             new Rank("МС")
                                         };

        public static Rank GetRankByName(string name)
        {
            return Ranks.First(r => r.Title.Equals(name));
        }

        public string Title;

        /// <summary>
        /// Do not use this constructor - it is only for initializing Ranks.
        /// </summary>
        public Rank(string title = null)
        {
            Title = title;
        }

        /// <summary>
        /// Do not use this constructor - it is only for serializing.
        /// </summary>
        public Rank()
        {
        }

        public static  Rank EmptyRank()
        {
            return Ranks[0];
        }

        public override string ToString()
        {
            return Title;
        }
    }
}
